from flask import Flask, request, jsonify
from flask_cors import CORS
from app.service.user_service import ask_ai

app = Flask(__name__)
CORS(app)  #允许所有跨域
each_chat = ask_ai()

@app.get('api/user/ai')
def chat():#问答
    content = request.get_json()
    user_ask = content.get('user_ask')
    if not user_ask:
        #如果user_ask为空
        return jsonify({"error": "请先输入问题"}), 400

    res = each_chat.ai_chat(user_ask)
    return jsonify({"response":res})

